using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;

using RecruitmentSystem.Common;

namespace RecruitmentSystem.DataAccess
{
    public class JobAccessor
    {
        public bool AddPosition(JobPosition position)
        {
            const string SpName = "SpAddPosition";

            try
            {
                object[] parameters = new object[]
                {
                    position.EnterpriseId,
                    position.Title,
                    position.PoitionType,
                    position.PublishDate,
                    position.EndDate,
                    position.ExperienceRequired,
                    position.KnowledgeRequired,
                    position.CandidateNumber,
                    position.LanguageAbility,
                    position.WorkProvince,
                    position.WorkDistrict,
                    position.Description,
                    position.WorkMethod,
                    position.AgeRequired,
                    position.Salary,
                    position.GenderRequired,
                    position.Department,
                    position.EmailAddress,
                    position.Telephone,
                    position.ContactAddress,
                    position.ContactPerson,
                    position.Remark,
                    position.DetailsTreatment,
                    position.PositionRequired
                };

                SqlHelper.ExecuteNonQuery(Constants.ConnectionString, SpName, parameters);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in add position", ex);
            }

            return true;
        }

        public bool UpdatePositionStatus(int id, PositionStatus type)
        {
            const string SpName = "SpChnagePositionStatus";

            try
            {
                object[] parameters = new object[]
                {
                    id,
                    Convert.ToInt32(type)
                };

                SqlHelper.ExecuteNonQuery(Constants.ConnectionString, SpName, parameters);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in update position status", ex);
            }

            return true;
        }

        public bool UpdatePositionById(JobPosition position)
        {
            const string SpName = "SpUpdatePositionById";

            try
            {
                object parameters = new object[]
                {
                    position.Id,
                    position.EnterpriseId,
                    position.Title,
                    position.PoitionType,
                    position.PublishDate,
                    position.EndDate,
                    position.ExperienceRequired,
                    position.KnowledgeRequired,
                    position.CandidateNumber,
                    position.LanguageAbility,
                    position.WorkProvince,
                    position.WorkDistrict,
                    position.Description,
                    position.Status,
                    position.WorkMethod,
                    position.AgeRequired,
                    position.Salary,
                    position.GenderRequired,
                    position.Department,
                    position.EmailAddress,
                    position.Telephone,
                    position.ContactAddress,
                    position.ContactPerson,
                    position.Remark,
                    position.DetailsTreatment,
                    position.PositionRequired
                };

                SqlHelper.ExecuteNonQuery(Constants.ConnectionString, SpName, parameters);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in update position", ex);
            }

            return true;
        }

        public List<JobPosition> GetPositionsByEnterpriseUserId(int userId,
            PositionStatus type,int pagesize,int pagecurrent)
        {
            List<JobPosition> positions = new List<JobPosition>();
            const string SpName = "SpGetPositionsByEnterpriseUserId";
            SqlDataReader reader = null;

            try
            {
                object[] parameters = new object[]
                {
                    pagesize,
                    pagecurrent,
                    userId,
                    Convert.ToInt32(type)
                };

                reader = SqlHelper.ExecuteReader(Constants.ConnectionString,
                    SpName, parameters);

                while (reader.Read())
                {
                    JobPosition position = new JobPosition();

                    position.Id = reader.GetInt32(0);
                    position.EnterpriseId = reader.GetInt32(1);
                    position.Title = !reader.IsDBNull(2) ? reader.GetString(2) : null;
                    position.PoitionType = !reader.IsDBNull(3) ? reader.GetString(3) : null;
                    position.PublishDate = reader.GetDateTime(4);
                    position.EndDate = reader.GetDateTime(5);
                    position.ExperienceRequired = reader.GetInt32(6);
                    position.KnowledgeRequired = !reader.IsDBNull(7) ? reader.GetString(7) : null;
                    position.CandidateNumber = !reader.IsDBNull(8) ? reader.GetString(8) : null;
                    position.LanguageAbility = !reader.IsDBNull(9) ? reader.GetString(9) : null;
                    position.WorkProvince = !reader.IsDBNull(10) ? reader.GetString(10) : null;
                    position.WorkDistrict = !reader.IsDBNull(11) ? reader.GetString(11) : null;
                    position.Description = !reader.IsDBNull(12) ? reader.GetString(12) : null;
                    position.Status = reader.GetString(13).ToString();
                    position.WorkMethod = !reader.IsDBNull(14) ? reader.GetString(14) : null;
                    position.AgeRequired = !reader.IsDBNull(15) ? reader.GetString(15) : null;
                    position.Salary = !reader.IsDBNull(16) ? reader.GetString(16) : null;
                    position.GenderRequired = !reader.IsDBNull(17) ? reader.GetString(17) : null;
                    position.Department = !reader.IsDBNull(18) ? reader.GetString(18) : null;
                    position.EmailAddress = !reader.IsDBNull(19) ? reader.GetString(19) : null;
                    position.Telephone = !reader.IsDBNull(20) ? reader.GetString(20) : null;
                    position.ContactPerson = !reader.IsDBNull(21) ? reader.GetString(21) : null;
                    position.ContactAddress = !reader.IsDBNull(22) ? reader.GetString(22) : null;
                    position.Remark = !reader.IsDBNull(23) ? reader.GetString(23) : null;
                    position.DetailsTreatment = !reader.IsDBNull(24) ? reader.GetString(24) : null;
                    position.PositionRequired = !reader.IsDBNull(25) ? reader.GetString(25) : null;

                    positions.Add(position);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in get positions for enterprise user",
                    ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return positions;
        }

        public List<JobPosition> GetPositionsByPersonalUserId(int userId,
            PositionStatus type, int pagesize, int pagecurrent)
        {
            List<JobPosition> positions = new List<JobPosition>();
            const string SpName = "SpGetPositionsByPersonalUserId";
            SqlDataReader reader = null;

            try
            {
                object[] parameters = new object[]
                {
                    pagesize,
                    pagecurrent,
                    userId,
                    Convert.ToInt32(type)
                };

                reader = SqlHelper.ExecuteReader(Constants.ConnectionString,
                    SpName, parameters);

                while (reader.Read())
                {
                    JobPosition position = new JobPosition();

                    position.Id = reader.GetInt32(0);
                    position.EnterpriseId = reader.GetInt32(1);
                    position.Title = !reader.IsDBNull(2) ? reader.GetString(2) : null;
                    position.PoitionType = !reader.IsDBNull(3) ? reader.GetString(3) : null;
                    position.PublishDate = reader.GetDateTime(4);
                    position.EndDate = reader.GetDateTime(5);
                    position.ExperienceRequired = reader.GetInt32(6);
                    position.KnowledgeRequired = !reader.IsDBNull(7) ? reader.GetString(7) : null;
                    position.CandidateNumber = !reader.IsDBNull(8) ? reader.GetString(8) : null;
                    position.LanguageAbility = !reader.IsDBNull(9) ? reader.GetString(9) : null;
                    position.WorkProvince = !reader.IsDBNull(10) ? reader.GetString(10) : null;
                    position.WorkDistrict = !reader.IsDBNull(11) ? reader.GetString(11) : null;
                    position.Description = !reader.IsDBNull(12) ? reader.GetString(12) : null;
                    position.Status = reader.GetString(13).ToString();
                    position.WorkMethod = !reader.IsDBNull(14) ? reader.GetString(14) : null;
                    position.AgeRequired = !reader.IsDBNull(15) ? reader.GetString(15) : null;
                    position.Salary = !reader.IsDBNull(16) ? reader.GetString(16) : null;
                    position.GenderRequired = !reader.IsDBNull(17) ? reader.GetString(17) : null;
                    position.Department = !reader.IsDBNull(18) ? reader.GetString(18) : null;
                    position.EmailAddress = !reader.IsDBNull(19) ? reader.GetString(19) : null;
                    position.Telephone = !reader.IsDBNull(20) ? reader.GetString(20) : null;
                    position.ContactPerson = !reader.IsDBNull(21) ? reader.GetString(21) : null;
                    position.ContactAddress = !reader.IsDBNull(22) ? reader.GetString(22) : null;
                    position.Remark = !reader.IsDBNull(23) ? reader.GetString(23) : null;
                    position.DetailsTreatment = !reader.IsDBNull(24) ? reader.GetString(24) : null;
                    position.PositionRequired = !reader.IsDBNull(25) ? reader.GetString(25) : null;
                    position.ApplyDate = reader.GetDateTime(26);
                    position.EnterpriseName = !reader.IsDBNull(27) ? reader.GetString(27) : null;
                    positions.Add(position);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in get positions for personal user",
                    ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return positions;
        }

        public List<JobPosition> GetPositionsByAdminUserId(int userId,
            PositionStatus type, int pagesize, int pagecurrent)
        {
            List<JobPosition> positions = new List<JobPosition>();
            const string SpName = "SpGetPositionsByAdminUserId";
            SqlDataReader reader = null;

            try
            {
                object[] parameters = new object[]
                {
                    pagesize,
                    pagecurrent,
                    userId,
                    Convert.ToInt32(type)
                };

                reader = SqlHelper.ExecuteReader(Constants.ConnectionString,
                    SpName, parameters);

                while (reader.Read())
                {
                    JobPosition position = new JobPosition();

                    position.Id = reader.GetInt32(0);
                    position.EnterpriseId = reader.GetInt32(1);
                    position.Title = !reader.IsDBNull(2) ? reader.GetString(2) : null;
                    position.PoitionType = !reader.IsDBNull(3) ? reader.GetString(3) : null;
                    position.PublishDate = reader.GetDateTime(4);
                    position.EndDate = reader.GetDateTime(5);
                    position.ExperienceRequired = reader.GetInt32(6);
                    position.KnowledgeRequired = !reader.IsDBNull(7) ? reader.GetString(7) : null;
                    position.CandidateNumber = !reader.IsDBNull(8) ? reader.GetString(8) : null;
                    position.LanguageAbility = !reader.IsDBNull(9) ? reader.GetString(9) : null;
                    position.WorkProvince = !reader.IsDBNull(10) ? reader.GetString(10) : null;
                    position.WorkDistrict = !reader.IsDBNull(11) ? reader.GetString(11) : null;
                    position.Description = !reader.IsDBNull(12) ? reader.GetString(12) : null;
                    position.Status = reader.GetString(13).ToString();
                    position.WorkMethod = !reader.IsDBNull(14) ? reader.GetString(14) : null;
                    position.AgeRequired = !reader.IsDBNull(15) ? reader.GetString(15) : null;
                    position.Salary = !reader.IsDBNull(16) ? reader.GetString(16) : null;
                    position.GenderRequired = !reader.IsDBNull(17) ? reader.GetString(17) : null;
                    position.Department = !reader.IsDBNull(18) ? reader.GetString(18) : null;
                    position.EmailAddress = !reader.IsDBNull(19) ? reader.GetString(19) : null;
                    position.Telephone = !reader.IsDBNull(20) ? reader.GetString(20) : null;
                    position.ContactPerson = !reader.IsDBNull(21) ? reader.GetString(21) : null;
                    position.ContactAddress = !reader.IsDBNull(22) ? reader.GetString(22) : null;
                    position.Remark = !reader.IsDBNull(23) ? reader.GetString(23) : null;
                    position.DetailsTreatment = !reader.IsDBNull(24) ? reader.GetString(24) : null;
                    position.PositionRequired = !reader.IsDBNull(25) ? reader.GetString(25) : null;
                    position.EnterpriseName = !reader.IsDBNull(26) ? reader.GetString(26) : null;

                    positions.Add(position);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in get positions for admin user",
                    ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return positions;
        }

        public List<JobPosition> GetPositionsByEnterpriseUserId(int userId,
            PositionStatus type)
        {
            List<JobPosition> positions = new List<JobPosition>();
            const string SpName = "SpGetPositionsByHotEnterpriseUserId";
            SqlDataReader reader = null;

            try
            {
                object[] parameters = new object[]
                {
                    userId,
                    Convert.ToInt32(type)
                };

                reader = SqlHelper.ExecuteReader(Constants.ConnectionString,
                    SpName, parameters);

                while (reader.Read())
                {
                    JobPosition position = new JobPosition();

                    position.Id = reader.GetInt32(0);
                    position.Title = !reader.IsDBNull(1) ? reader.GetString(1) : null;

                    positions.Add(position);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in get positions for hot enterprise user",
                    ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return positions;
        }

        public bool DeletePosition(int id)
        {
            const string SpName = "SpDeletePositionById";

            try
            {
                object[] parameters = new object[]
                {
                    id
                };

                SqlHelper.ExecuteNonQuery(Constants.ConnectionString, SpName, parameters);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in delete position", ex);
            }

            return true;
        }

        public JobPosition GetPosition(int id)
        {
            JobPosition position = null;
            const string SpName = "SpGetPositionById";
            SqlDataReader reader = null;

            try
            {
                object[] parameters = new object[]
                {
                    id
                };

                reader = SqlHelper.ExecuteReader(Constants.ConnectionString,
                    SpName, parameters);

                while (reader.Read())
                {
                    position = new JobPosition();

                    position.Id = reader.GetInt32(0);
                    position.EnterpriseId = reader.GetInt32(1);
                    position.Title = !reader.IsDBNull(2) ? reader.GetString(2) : null;
                    position.PoitionType = !reader.IsDBNull(3) ? reader.GetString(3) : null;
                    position.PublishDate = reader.GetDateTime(4);
                    position.EndDate = reader.GetDateTime(5);
                    position.ExperienceRequired = reader.GetInt32(6);
                    position.KnowledgeRequired = !reader.IsDBNull(7) ? reader.GetString(7) : null;
                    position.CandidateNumber = !reader.IsDBNull(8) ? reader.GetString(8) : null;
                    position.LanguageAbility = !reader.IsDBNull(9) ? reader.GetString(9) : null;
                    position.WorkProvince = !reader.IsDBNull(10) ? reader.GetString(10) : null;
                    position.WorkDistrict = !reader.IsDBNull(11) ? reader.GetString(11) : null;
                    position.Description = !reader.IsDBNull(12) ? reader.GetString(12) : null;
                    position.Status = reader.GetString(13).ToString();
                    position.WorkMethod = !reader.IsDBNull(14) ? reader.GetString(14) : null;
                    position.AgeRequired = !reader.IsDBNull(15) ? reader.GetString(15) : null;
                    position.Salary = !reader.IsDBNull(16) ? reader.GetString(16) : null;
                    position.GenderRequired = !reader.IsDBNull(17) ? reader.GetString(17) : null;
                    position.Department = !reader.IsDBNull(18) ? reader.GetString(18) : null;
                    position.EmailAddress = !reader.IsDBNull(19) ? reader.GetString(19) : null;
                    position.Telephone = !reader.IsDBNull(20) ? reader.GetString(20) : null;
                    position.ContactPerson = !reader.IsDBNull(21) ? reader.GetString(21) : null;
                    position.ContactAddress = !reader.IsDBNull(22) ? reader.GetString(22) : null;
                    position.Remark = !reader.IsDBNull(23) ? reader.GetString(23) : null;
                    position.DetailsTreatment = !reader.IsDBNull(24) ? reader.GetString(24) : null;
                    position.PositionRequired = !reader.IsDBNull(25) ? reader.GetString(25) : null;
                }

            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in delete position", ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return position;
        }

        public int GetJobsCountByEnterpriseUserId(int id, PositionStatus type)
        {
            const string SpName = "GetJobsCountByEnterpriseUserId";
            int count = 0;

            try
            {
                object[] parameters = new object[]
                {
                    id,
                    Convert.ToInt32(type)
                };

                object o = SqlHelper.ExecuteScalar(Constants.ConnectionString, SpName, parameters);

                if (o != null)
                {
                    count = Convert.ToInt32(o);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in get jobs count", ex);
            }

            return count;
        }

        public int GetJobsCountByPersonalUserId(int id, PositionStatus type)
        {
            const string SpName = "SpGetJobsCountByPersonalUserId";
            int count = 0;

            try
            {
                object[] parameters = new object[]
                {
                    id,
                    Convert.ToInt32(type)
                };

                object o = SqlHelper.ExecuteScalar(Constants.ConnectionString, SpName, parameters);

                if (o != null)
                {
                    count = Convert.ToInt32(o);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in get jobs count", ex);
            }

            return count;
        }

        public int GetJobsCountByAdminUserId(int id, PositionStatus type)
        {
            const string SpName = "SpGetJobsCountByAdminUserId";
            int count = 0;

            try
            {
                object[] parameters = new object[]
                {
                    id,
                    Convert.ToInt32(type)
                };

                object o = SqlHelper.ExecuteScalar(Constants.ConnectionString, SpName, parameters);

                if (o != null)
                {
                    count = Convert.ToInt32(o);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in get jobs count", ex);
            }

            return count;
        }

        public bool ApplyPosition(int positionId, int userId, UserType type)
        {
            const string SpName = "SpApplyPosition";

            try
            {
                object[] parameters = new object[]
                {
                    positionId,
                    userId,
                    Convert.ToInt32(type)
                };

                object o = SqlHelper.ExecuteScalar(Constants.ConnectionString, SpName, parameters);

                if (o != null)
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in delete position", ex);
            }

            return true;
        }

        public List<Link> GetLinks()
        {
            List<Link> links = new List<Link>();
            const string SpName = "SpGetLinks";
            SqlDataReader reader = null;

            try
            {
                object[] parameters = new object[] { };

                reader = SqlHelper.ExecuteReader(Constants.ConnectionString,
                    SpName, parameters);

                while (reader.Read())
                {
                    Link link = new Link();

                    link.Id = reader.GetInt32(0);
                    link.Name = !reader.IsDBNull(1) ? reader.GetString(1) : null;
                    link.Address = !reader.IsDBNull(2) ? reader.GetString(2) : null;

                    links.Add(link);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in get links", ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return links;
        }

        public bool AddLink(Link link)
        {
            const string SpName = "SpAddLink";

            try
            {
                object[] parameters = new object[]
                {
                    link.Name,
                    link.Address
                };

                SqlHelper.ExecuteNonQuery(Constants.ConnectionString, SpName, parameters);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in add link", ex);
            }

            return true;
        }

        public bool UpdateLink(Link link)
        {
            const string SpName = "SpUpdateLink";

            try
            {
                object[] parameters = new object[]
                {
                    link.Id,
                    link.Name,
                    link.Address
                };

                SqlHelper.ExecuteNonQuery(Constants.ConnectionString, SpName, parameters);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in update link", ex);
            }

            return true;
        }

        public bool RemoveLink(int id)
        {
            const string SpName = "SpDeleteLink";

            try
            {
                object[] parameters = new object[]
                {
                    id
                };

                SqlHelper.ExecuteNonQuery(Constants.ConnectionString, SpName, parameters);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception occurs in remove link", ex);
            }

            return true;
        }

        public List<JobPosition> GetPositions(string positionType, string workProvince,
            string workDistrict, string salary, string genderRequired, string workMethod,
            string title, string enterpriseType, string category, int pageCurrent, int pageSize)
        {
            List<JobPosition> positions = new List<JobPosition>();
            const string SpName = "SpSearchPositions";
            SqlDataReader reader = null;

            try
            {
                object[] parameters = new object[]
                {
                    positionType,
                    workProvince,
                    workDistrict,
                    salary,
                    genderRequired,
                    workMethod,
                    title,
                    enterpriseType,
                    category,
                    pageCurrent.ToString(),
                    pageSize.ToString()
                };

                reader = SqlHelper.ExecuteReader(Constants.ConnectionString,
                    SpName, parameters);

                while (reader.Read())
                {
                    JobPosition position = new JobPosition();

                    position.Id = reader.GetInt32(0);
                    position.Title = !reader.IsDBNull(1) ? reader.GetString(1) : null;
                    position.EnterpriseName = !reader.IsDBNull(2) ? reader.GetString(2) : null;
                    position.EnterpriseId = reader.GetInt32(3);
                    position.PublishDate = reader.GetDateTime(4);

                    positions.Add(position);

                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in search positions",
                    ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return positions;
        }

        public int GetPositionsCount(string positionType, string workProvince,
            string workDistrict, string salary, string genderRequired, string workMethod,
            string title, string enterpriseType, string category)
        {
            int count = 0;

            const string SpName = "SpGetSearchPositionsCount";

            try
            {
                object[] parameters = new object[]
                {
                    positionType,
                    workProvince,
                    workDistrict,
                    salary,
                    genderRequired,
                    workMethod,
                    title,
                    enterpriseType,
                    category
                };

                object o = SqlHelper.ExecuteScalar(Constants.ConnectionString,
                    SpName, parameters);

                if (o != null)
                {
                    count = Convert.ToInt32(o);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in get positions count",
                    ex);
            }

            return count;
        }

        public List<UserPosition> GetUserPositions(string name,
            string enterpriseName, string positionName, int pageCurrent, int pageSize)
        {
            List<UserPosition> positions = new List<UserPosition>();
            const string SpName = "SpGetUserPositionsForPersonalUser";
            SqlDataReader reader = null;
            
            try
            {
                object[] parameters = new object[]
                {
                    pageCurrent.ToString(),
                    pageSize.ToString(),
                    name,
                    enterpriseName,
                    positionName
                };

                reader = SqlHelper.ExecuteReader(Constants.ConnectionString,
                    SpName, parameters);

                while (reader.Read())
                {
                    UserPosition position = new UserPosition();

                    position.UserId = reader.GetInt32(0);
                    position.Name = !reader.IsDBNull(1) ? reader.GetString(1) : null;
                    position.PositionId = reader.GetInt32(2);
                    position.Title = !reader.IsDBNull(3) ? reader.GetString(3) : null;
                    position.EnterpriseId = reader.GetInt32(4);
                    position.EnterpriseName = !reader.IsDBNull(5) ? reader.GetString(5) : null;
                    position.ApplyDate = !reader.IsDBNull(6) ? reader.GetDateTime(6) : (DateTime?)null;
                    position.UserType = UserType.SchoolUser;

                    positions.Add(position);

                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in get user and positions",
                    ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return positions;
        }

        public int GetUserPositionsCount(string name,
            string enterpriseName, string positionName)
        {
            int count = 0;
            const string SpName = "SpGetUserPositionsForPersonalUserCount";

            try
            {
                object[] parameters = new object[]
                {
                    name,
                    enterpriseName,
                    positionName
                };

                object o = SqlHelper.ExecuteScalar(Constants.ConnectionString,
                    SpName, parameters);

                if (o != null)
                {
                    count = Convert.ToInt32(o);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception occurs in get user positions count",
                    ex);
            }

            return count;
        }
    }
}
